/**
 * @(#)Main.java 2011-8-24 Copyright 2011 it.kedacom.com, Inc. All rights
 *               reserved.
 */

package com.kedacom.xmpp.demo.oneserver.pubsub;

import java.util.Iterator;

import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverInfo.Feature;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.pubsub.PubSubManager;

/**
 * (用一句话描述类的主要功能)
 * @author xiaojinghai
 * @date 2011-8-24
 */

public class DiscoverNodes {

	/**
	 * (用一句话描述方法的主要功能)
	 * @param args
	 * @throws XMPPException
	 */

	public static void main(String[] args) throws XMPPException {
		Connection.DEBUG_ENABLED = true;
		String SERVER = "kedacom.com", RESOURCE = "java", USER1 = "admin", PASS1 = "itserver";
		Connection conn1 = null;

		// 连接与登录
		conn1 = new XMPPConnection(SERVER);
		conn1.connect();
		conn1.login(USER1, PASS1, RESOURCE);

		// 获得pub/sub管理器
		PubSubManager mgr = new PubSubManager(conn1);

		DiscoverInfo supportedFeatures = mgr.getSupportedFeatures();
		Iterator<Feature> features = supportedFeatures.getFeatures();
		System.out.println("=======================特性列表=======================");
		while (features.hasNext()) {
			Feature feature = features.next();
			System.out.println(feature.getVar());
		}
		System.out.println("=======================特性列表=======================");

		System.out.println("=======================所有节点=======================");
		DiscoverItems nodes = mgr.discoverNodes(null);
		Iterator<DiscoverItems.Item> items = nodes.getItems();
		while (items.hasNext()) {
			DiscoverItems.Item item = items.next();
			System.out.println("Node:" + item.getNode() + ",Action:" + item.getAction() + ",Name:" + item.getName()
					+ ",EntityID:" + item.getEntityID());
		}
		System.out.println("=======================所有节点=======================");

	}
}
